/**
 * 添加或者修改页面
 */
var TeamInfoDlg = {
    data: {
        id: "",
        teamTitle: "",
        specialtyId: "",
        source: "",
        createTime: "",
        endTime: "",
        status: "",
        lastEndTime: "",
        lecturerId: "",
        teacherId: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var laydate = layui.laydate;
    var admin = layui.admin;

    //初始化时间选择器
    laydate.render({
        elem: '#endTime'
        , type: 'datetime'
        ,format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#lastEndTime'
        , type: 'datetime'
        ,format: 'yyyy-MM-dd'
    });

    getSpecialtyType();
    showTeachers();

    //获取专业类型并展示
    function getSpecialtyType() {
        var ajax = new $ax(Feng.ctxPath + "/specialtyType/showList");
        var result = ajax.start();
        $('#specialtyId').append('<option value=""></option>');
        result.data.map(item =>{
            $('#specialtyId').append('<option value="'+item.id+'">'+item.typeName+'</option>');
        });
        form.render('select');
    }

    //获取讲师及班主任
    function showTeachers(){
        var ajax = new $ax(Feng.ctxPath + "/team/showTeachers");
        var result = ajax.start();
        $('#lecturerId').append('<option value="">请选择授课讲师</option><optgroup label="专业高级阶段讲师">');
        result.data.zhuanyegaoji.map(item =>{
            $('#lecturerId').append('<option value="'+item.userId+'">'+item.name+'</option>');
        });
        $('#lecturerId').append('</optgroup><optgroup label="项目实训就业阶段讲师">');
        result.data.shixun.map(item =>{
            $('#lecturerId').append('<option value="'+item.userId+'">'+item.name+'</option>');
        });
        $('#lecturerId').append('</optgroup>');
        $('#teacherId').append('<option value="">请选择班主任</option>');
        result.data.banzhuren.map(item =>{
            $('#teacherId').append('<option value="'+item.userId+'">'+item.name+'</option>');
        });
        form.render('select');
    }

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/team/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });


});